<HTML><HEAD><TITLE>use_module(++ModuleFile)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Modules</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>use_module(++ModuleFile)</H1>
Load and import the module from the given ModuleFile.
<DL>
<DT><EM>ModuleFile</EM></DT>
<DD>Atom, String, compound term library(Name), or a list of such.
</DD>
</DL>
<H2>Description</H2>
   This is a combination of ensure_loaded/1 and import/1, i.e. it
   loads a module file and imports everything the module exports.
<P>
   ModuleFile is a module name, a source file name, a library
   specification (e.g. library(util)) or a list of such items. 
   First, ModuleFile is converted to a file name and that file is
   loaded, compiled or recompiled as with ensure_loaded/1.
   Then, a module name is extracted from the base name of ModuleFile
   (the loading is expected to create that module, i.e. the file is
   expected to follow the naming convention for module files).
   That module is then imported as with import/1.
<P>
   The rules for finding the source file from the ModuleFile specification
   are the same as for ensure_loaded/1 and compile/1, i.e. object or
   source file suffixes are appended, and the library path is searched
   if the name is specified as library(FileName).

<H3>Modes and Determinism</H3><UL>
<LI>use_module(++) is det
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Module is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Module is instantiated, but not to an atom.
<DT><EM>(80) not a module </EM>
<DD>Module is not defined in the compiled file.
<DT><EM>(171) File does not exist :  </EM>
<DD>The file does not exist or is not readable.
</DL>
<H2>Examples</H2>
<PRE>
Success:
    :- use_module(library(util)).
    :- use_module("/usr/local/eclipse/lib/util").
    :- use_module(util).
    :- use_module("util.pl").


Error:
    :- use_module(M).                      (Error 4).
    :- use_module(file(f)).                (Error 5).
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/modules/module-1.html">module / 1</A>, <A HREF="../../kernel/modules/module-3.html">module / 3</A>, <A HREF="../../kernel/compiler/compile-1.html">compile / 1</A>, <A HREF="../../kernel/compiler/ensure_loaded-1.html">ensure_loaded / 1</A>, <A HREF="../../kernel/modules/import-1.html">import / 1</A>, <A HREF="../../kernel/compiler/lib-1.html">lib / 1</A>, <A HREF="../../kernel/opsys/existing_file-4.html">existing_file / 4</A>
</BODY></HTML>
